package modelLayer;

import java.util.ArrayList;
/**
 * Write a description of class LoanContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class LoanContainer
{
    // instance variables - replace the example below with your own
    private ArrayList<Loan> loanList;
    private static LoanContainer instance;
    /**
     * Constructor for objects of class LoanContainer
     */
    private LoanContainer()
    {
        loanList = new ArrayList<Loan>();
    }

    public void addLoan(Loan loan)
    {
        loanList.add(loan);
    }
    
    public static LoanContainer getInstance() 
    {
        if(instance == null) 
        {
            instance = new LoanContainer();
        }
        return instance;
    }
    
    // Get loan
    public Loan getLoan(String id) 
    {
        Loan returnLoan = null;
        for(Loan loan : loanList) 
        {
            if(loan.getId().equals(id))
            {
                returnLoan = loan;
            }
        }
        return returnLoan;
    }
    
    // Update a loan
    public void updateLoan(Loan loan, String period) {
        loan.setPeriod(period);
    }
    
    // Delete a loan
    public void deleteLoan(Loan loan) 
    {
        loanList.remove(loan);
    }
    
    // Update state = Register return
    public void registerReturn(Loan loan, String newState) 
    {
        loan.setState(newState);
    }
}
